package com.zhang.controller;

import com.zhang.entity.response.ResponseResult;
import com.zhang.entity.vo.SaveRedisBody;
import com.zhang.util.RedisUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * User: 张
 * Date: 2024-11-16
 * Time: 19:15
 * Description:
 */
@RestController
public class RedisController {
    @Autowired
    private RedisUtil redisUtil;

    @PostMapping("/saveRedis")
    public ResponseResult<Object> saveRedis(@RequestBody SaveRedisBody saveRedisBody){
        redisUtil.set(saveRedisBody.getKey(), saveRedisBody.getValue());
        return ResponseResult.success();
    }
    @PostMapping("/removeRedis")
    public ResponseResult<Object> removeRedis(String key){
        redisUtil.popValue(key);
        return ResponseResult.success();
    }

    @GetMapping("/getRedis")
    public ResponseResult<Object> getRedis(String key){
        return ResponseResult.success(redisUtil.get(key));
    }
}
